<?php

class Application_Model_User {

    public function LoginValidate($username, $password) {
        $db = Zend_Registry::get('dbAdapter');
        $auth = Zend_Auth::getInstance();

        $authAdapter = new Zend_Auth_Adapter_DbTable($db);
        $authAdapter->setTableName('tbl_user')
                ->setIdentityColumn('username')
                ->setCredentialColumn('password');

        $authAdapter->setIdentity($username);
        $password = md5($password);
        $authAdapter->setCredential($password);

        $result = $auth->authenticate($authAdapter);
        if ($result->isValid()) {
            $data = $authAdapter->getResultRowObject(null, array('password'));
            $auth->getStorage()->write($data);
            return true;
        }
        return false;
    }

}
